<?php

namespace app\admin\controller;

use app\common\model\Admin;
use app\common\model\Rule;
use think\Request;

class Category extends Common
{
    public function menu(){
        $uid=session(config('auth.ADMIN_AUTH_KEY'));
        $cate=Rule::where(['status'=>1,'showed'=>1])->order('id','asc')->select();
        $cates=[];
        if(in_array($uid,config('auth.ADMINISTRATOR'))){
            $cates=$cate;
        }else{
            $user=Admin::field('password',true)->find($uid);
            $group=$user->authGroup;
            $rid='';
            foreach($group as $g){
                $rid.=$g['rules'].',';
            }
            $rids=array_filter(array_unique(explode(',',$rid)));

            foreach($cate as $v){
                if(in_array($v['id'],$rids)){
                    $cates[]=$v;
                }
            }
        }
        $pid=input('post.id');
        $res=[
            'status'=>200,
            'data'=>menu($cates,$pid)
        ];
        return json_encode($res);
    }
}
